<?php
  require_once 'DB.php';
  include_once("./libraries/db.inc.php");
  include_once("./libraries/authentication.inc.php");
  include_once("./queries/matches.inc.php");
  include_once("./libraries/util.inc.php");
  include_once("./libraries/displayUtils.inc.php");
  include_once("./libraries/recordset.inc.php");

  session_start();
  sessionAuthenticate("login.php");

  $dataIndex = "matchList";
  
  $refresh = false;
  $queryType = -1;
  $params = array();
  $status = array();
  $displayPage = 1;
  $interval = "unknown";

  //process the get variables
  foreach ($_GET as $varName => $value) {
	//echo "varName: {$varName}, value: {$value}\n";
	if ($varName == "refresh") {
	  $refresh=$value;
        } elseif ($varName == "qt") {
	   $queryType = $value;
        } elseif (($varName == "waiting" || 
                   $varName == "held" || 
                   $varName == "running" ||
                   $varName == "completed" ||
                   $varName == "removed"
                  ) && $value == "true") {
           $status[count($statusFilters)] = $varName;
           
        } elseif ($varName == "dP") {
            $displayPage = $value;
        } elseif ($varName == "interval") {
            $interval = $value;
        } else {
          //echo "{$varName}: {$value}\n";
          $params["{$varName}"] = $value;
        } 
  }

    //we need to get the data
    $connection = DB::connect($dsn, $options);
    if (DB::isError($connection)) {
      trigger_error($connection->getMessage(), E_USER_ERROR);
    }
    if ($interval == "unknown") $interval = "24 hours";

    
   $rs = single_proc_matchmaking_query($connection, 
                                           $dataIndex, 
                                           $params["schedd"], 
                                           $params["cid"], 
                                           $params["pid"],
                                           $params["matchTime"], 
                                           $displayPage);
    //echo "called it";

    $connection->disconnect();

  //now we know we have data, so display it
 
  if ($_SESSION["administrator"] === true) {
    $rs->setLinkParams(2, array("mid"), array(2), "machineInfo.php");
  }
  //$rs->complexSetLinkParams(2, array("schedd","cid","pid"), array(0,1,2));
  //$rs->linkFile = "procHistoryInfo.php";
  //echo "Size is now: {$rs->recordCount}";
  $rs->printNavigablePage($_SESSION["{$dataIndex}"]["title"],
                          $_SESSION["{$dataIndex}"]["message"],
                          $displayPage,
                          "./matchList.php");
  cdbFinishPage();

?>
